<template>
	<view class="doctorTransfer">
		<searchBox :currentCode='currentCode' @handleSearch='handleSearch'></searchBox>
		<view class="content" v-if="ordersList.length>0">
			<transferItem v-for="(item, index) in ordersList" :key="index" :orderObj='item' :itemIndex='index'
				:btnGroupArr="btnGroupArr" @handleClick="consultationTableButtonClick"></transferItem>
			<view class="loadmoreView">
				<u-loadmore :status="status" />
			</view>

		</view>
		<pagesNoData v-else></pagesNoData>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		serviceStatusMap,
		ningboOrderTypeMap,
		ordersStatusMap
	} from '@/utils/baseData.js'
	import transferItem from '@/components/common/transferItem.vue'
	import {
		postDiagnosisHistoryList
	} from '@/api/platform/diagnosis_history.js'

	export default {
		name: "doctorTransfer",
		components: {
			transferItem,
		},
		props: {
			currentCode: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				serviceStatusMap: serviceStatusMap,
				ningboOrderTypeMap: ningboOrderTypeMap,
				ordersStatusMap: ordersStatusMap,
				transferInfoStatusArrText: {
					0: '未上传',
					1: '已上传'
				},
				ordersList: [],
				btnGroupArr: [{
						label: '上传',
						functionKey: 'upload'
					},
					{
						label: '详情',
						functionKey: 'transferInfoDetail'
					}
				],
				status: 'loadmore',
				total: 0,
				filterForm: {
					visitingHospitalId: '', //医院名称
					dataUploadStatus: '', //资料状态
					patientName: '', //患者姓名
					ward: '', //病区
					startTime: '', //开始日期
					endTime: '', //结束日期
					page: 0,
					size: 10
				},

			};
		},
		mounted() {
			this.diagnosisTableRequest()
		},
		methods: {
			handleSearch(data) {
				this.ordersList = []
				this.filterForm = data
				this.diagnosisTableRequest()
			},
			scrolltolower() {
				let that = this;
				this.status = 'loading';
				this.filterForm.page = ++this.filterForm.page;
				setTimeout(() => {
					if (this.ordersList.length < this.total) {
						this.status = 'loadmore'
						that.diagnosisTableRequest()
					} else {
						this.status = 'nomore'
					}

				}, 600)
			},
			diagnosisTableRequest() { //代转资料
				postDiagnosisHistoryList(this.filterForm).then(res => {
					if (res.code == 200) {
						this.total = res.pageInfo.total
						let ordersList = res.data
						ordersList.forEach((t, index) => {
							const institution = {
								id: t.orderId,
								index,
								createTime: t.createTime,
								diseaseLocation: t.diseaseLocation,
								consultationSerialNumber: t.id,
								serialNumber: t.serialNumber,
								serviceStatus: serviceStatusMap[t.serviceStatus],
								serviceStatusId: t.serviceStatus,
								ordersStatus: ordersStatusMap[t.ordersStatus],
								ordersStatusId: t.ordersStatus,
								dataUploadStatus: t.dataUploadStatus,
								dataUploadStatusText: this.transferInfoStatusArrText[t
									.dataUploadStatus],
								ordersStatusVal: t.ordersStatus,
								extrasRecorded: t.extrasRecorded,
								expressCount: t.expressCount,
								receiveWithoutSignInCount: t.receiveWithoutSignInCount,
								serviceCenterName: t.serviceCenterName,
								serviceProject: t.institutionServicesInfo?.name == null ? '' : t
									.institutionServicesInfo.name,
								amount: t.amount,
								visitingHospitalName: t.visitingHospitalName,
								name: t.patientsInfo.name,
								sexName: t.patientsInfo.sexName ? t.patientsInfo.sexName : '',
								cellphone: t.patientsInfo.cellphone,
								ageData: t.patientsInfo.age,
								companyStatus: t.companyStatus == 0 ? '不陪诊' : t.companyStatus == 0 ?
									'陪诊' : '',
								consultationType: t.typeOfConsultationName === '冰冻' ?
									`冰冻(${t.frozenAppointmentTime + t.morningAndAfternoonName})` : t
									.typeOfConsultationName,
								simpleKindId: t.patientsInfo.diagnosisHistory[0] ? t.patientsInfo
									.diagnosisHistory[0].specimenCategoryName : '',
								visceraName: t.patientsInfo.diagnosisHistory[0] ? t.patientsInfo
									.diagnosisHistory[0].visceraName : '',
								hospitalNumber: t.hospitalNumber ? t.hospitalNumber : t.patientsInfo
									.diagnosisHistory[0] ? t.patientsInfo.diagnosisHistory[0]
									.hospitalNumber : '',
								contactName: t.patientsInfo.contactName,
								contactCellphone: t.patientsInfo.contactCellphone,
								contactWeChat: t.patientsInfo.contactWeChat,
								sendingHospitalName: t.sendingHospitalName,
								sendingDoctor: t.sendingDoctor,
								sendingDoctorPhone: t.sendingDoctorPhone,
								orderTypeName: t.orderType == 1 ? '机构申请' : t.orderType == 2 ? '个人申请' :
									'',
								bedNo: t.bedNo ? t.bedNo : t.patientsInfo.diagnosisHistory[0] ? t
									.patientsInfo.diagnosisHistory[0].bedNo : '',
								ward: t.ward ? t.ward : t.patientsInfo.diagnosisHistory[0] ? t
									.patientsInfo.diagnosisHistory[0].ward : '',
							}
							this.ordersList.push(institution)
							if (this.ordersList.length < this.total) {
								this.status = 'loadmore'
							} else {
								this.status = 'nomore'
							}
						})
					}
				})

			},

			consultationTableButtonClick(functionKey, row) { // 总的事件方法
				this[functionKey](row)
			},
			upload(item) { //上传
				uni.navigateTo({
					url: `/subPackages/patient/detail/detail?id=${item.id}&current=2`
				})
			},
			transferInfoDetail(item) { //详情
				uni.navigateTo({
					url: `/subPackages/patient/detail/detail?id=${item.id}`
				})
			},
		}
	}
</script>

<style lang="scss">

</style>